/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iqq.ui;

import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import iqq.comm.IconTreeNode;
import iqq.comm.MyDefaultTreeCellRenderer;
import iqq.model.Group;
import iqq.model.Member;
import iqq.model.Message;
import iqq.service.GroupService;
import iqq.service.MessageService;
import iqq.util.GroupUtil;
import iqq.util.Log;
import iqq.util.QQImageUtil;
import iqq.util.ThreadUtil;

/**
 *
 * @author chenzhihui
 */
public class GroupChatPanel extends BaseChatPanel {

    private MainFrame mainFrame = MainFrame.getMainFrame();
    private Map map = mainFrame.getMap();
    private MessageService messageService = MessageService.getIntance();
    private Group group = null;
    private StringBuilder messages = new StringBuilder();
    private JTree groupMemberTree = null;
    private HTMLDocument sendText;
    private boolean isAddIQQinfo;

    public StringBuilder getMessages() {
        return messages;
    }

    public void setMessages(Message message) {
        //Log.println("group msg:" + message.getMessage());
        this.messages.append(message.toString());
        this.chatingTextPane.setText(this.messages.toString());
        this.chatingTextPane.setSelectionEnd(chatingTextPane.getText().length());
        this.validate();
        this.setVisible(true);
    }

    /**
     * Creates new form ChatPanel
     */
    public GroupChatPanel(Group group) throws Exception {
        initComponents();
        super.setId(group.getId());
        isAddIQQinfo = true;
        this.group = group;
        this.lblFace.setIcon(group.getFace());
        this.lblUsername.setText(group.getName());
        this.lblLnick.setText("");

        if (GroupUtil.getInstance().isDisabled(group.getId())) {
            btnEnabled.setIcon(disIcon);
        }
        this.validate();
        this.setVisible(true);
        initGroupMembers();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ChatPanelTop = new javax.swing.JPanel();
        lblFace = new javax.swing.JLabel();
        lblUsername = new javax.swing.JLabel();
        lblLnick = new javax.swing.JLabel();
        ChatToolBarTop = new javax.swing.JToolBar();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        ChatPanelBottom = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton4 = new javax.swing.JButton();
        btnFace = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        btnEnabled = new javax.swing.JButton();
        btnSend = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        chatingTextPane = new javax.swing.JTextPane();
        groupTreePanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        editorPane = new javax.swing.JEditorPane();

        lblFace.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/face.png"))); // NOI18N

        lblUsername.setText("承∮诺");

        lblLnick.setFont(new java.awt.Font("AR PL UMing CN", 0, 14)); // NOI18N
        lblLnick.setText("青山相伴，浊酒相随，菊花相依，归隐山林，自成乐趣，享受恬静幽雅的自然风光。");

        ChatToolBarTop.setFloatable(false);
        ChatToolBarTop.setRollover(true);
        ChatToolBarTop.add(jSeparator1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/group_homepage.png"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ChatToolBarTop.add(jButton1);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/group_share.png"))); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ChatToolBarTop.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/group_images.png"))); // NOI18N
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ChatToolBarTop.add(jButton3);

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/group_setting.png"))); // NOI18N
        jButton8.setFocusable(false);
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        ChatToolBarTop.add(jButton8);

        javax.swing.GroupLayout ChatPanelTopLayout = new javax.swing.GroupLayout(ChatPanelTop);
        ChatPanelTop.setLayout(ChatPanelTopLayout);
        ChatPanelTopLayout.setHorizontalGroup(
            ChatPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChatPanelTopLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFace)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ChatPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblUsername)
                    .addComponent(lblLnick, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(ChatToolBarTop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        ChatPanelTopLayout.setVerticalGroup(
            ChatPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChatPanelTopLayout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addGroup(ChatPanelTopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ChatPanelTopLayout.createSequentialGroup()
                        .addComponent(lblUsername)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblLnick, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblFace))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addComponent(ChatToolBarTop, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.add(jSeparator2);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/w.png"))); // NOI18N
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton4);

        btnFace.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/face.png"))); // NOI18N
        btnFace.setToolTipText("表情");
        btnFace.setFocusable(false);
        btnFace.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnFace.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnFace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFaceActionPerformed(evt);
            }
        });
        jToolBar1.add(btnFace);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/i.png"))); // NOI18N
        jButton6.setFocusable(false);
        jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton6);

        btnEnabled.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iqq/res/images/icon/group_enabled.png"))); // NOI18N
        btnEnabled.setToolTipText("禁用群信息");
        btnEnabled.setFocusable(false);
        btnEnabled.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEnabled.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEnabled.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEnabledActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEnabled);

        btnSend.setText("发送");
        btnSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendActionPerformed(evt);
            }
        });
        btnSend.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btnSendKeyPressed(evt);
            }
        });

        chatingTextPane.setBackground(java.awt.Color.white);
        chatingTextPane.setContentType("text/html");
        chatingTextPane.setEditable(false);
        chatingTextPane.setFocusable(false);
        jScrollPane3.setViewportView(chatingTextPane);

        groupTreePanel.setLayout(new java.awt.BorderLayout());

        jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 10)); // NOI18N
        jLabel1.setText("Ctrl+Enter");

        editorPane.setBackground(java.awt.SystemColor.text);
        editorPane.setContentType("text/html");
        editorPane.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                editorPaneKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(editorPane);

        javax.swing.GroupLayout ChatPanelBottomLayout = new javax.swing.GroupLayout(ChatPanelBottom);
        ChatPanelBottom.setLayout(ChatPanelBottomLayout);
        ChatPanelBottomLayout.setHorizontalGroup(
            ChatPanelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChatPanelBottomLayout.createSequentialGroup()
                .addGroup(ChatPanelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ChatPanelBottomLayout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(ChatPanelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel1)
                            .addComponent(btnSend, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12))
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(groupTreePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        ChatPanelBottomLayout.setVerticalGroup(
            ChatPanelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChatPanelBottomLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ChatPanelBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ChatPanelBottomLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnSend)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addContainerGap())))
            .addComponent(groupTreePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ChatPanelTop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(ChatPanelBottom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(ChatPanelTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(ChatPanelBottom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendActionPerformed
        // TODO add your handling code here:
        //this.editorPane.setLineWrap(true);
        if (editorPane.getDocument().getLength() == 0) {
            return;
        }
        int chatingTextLength = chatingTextPane.getDocument().getLength();
        if (isAddIQQinfo) {
            String from = "\n(Sent From iQQ For " + System.getProperty("os.name") + "...Web:http://code.google.com/p/iqq/)";
            try {
                editorPane.getDocument().insertString(editorPane.getDocument().getLength(), from, null);
            } catch (BadLocationException ex) {
                Logger.getLogger(ChatPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
            isAddIQQinfo = false;
        }

        HTMLDocument htmlDoc = new HTMLDocument();
        String text = QQImageUtil.parseHTML(editorPane.getText());
        try {
            htmlDoc.insertString(0, text, null);
        } catch (BadLocationException ex) {
            Logger.getLogger(ChatPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        HTMLDocument chatingHtmlDoc = (HTMLDocument) chatingTextPane.getDocument();
        HTMLEditorKit kit = (HTMLEditorKit) chatingTextPane.getEditorKit();
        Member mySelf = (Member) map.get("member");
        Message message = new Message();
        message.setGroup(group);
        message.setMember(mySelf);
        message.setCreateDate(new Date());
        message.setMessage(htmlDoc);

        this.messages.append(message.toString());

        try {
            //chatingHtmlDoc.insertString(chatingHtmlDoc.getLength(), htmlDoc.getText(0, htmlDoc.getLength()), null);
            kit.insertHTML(chatingHtmlDoc, chatingHtmlDoc.getLength(), message.toString(), 0, 0, null);
        } catch (Exception ex) {
            Logger.getLogger(ChatPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        sendText = (HTMLDocument) this.editorPane.getDocument();
        //this.chatingTextPane.setText(this.messages.toString());
        //this.editorPane.setText("");

        Runnable r = new Runnable() {

            public void run() {
                messageService.sendGroupMsg(group.getId(), sendText);
            }
        };
        ThreadUtil.submit(r);
        this.chatingTextPane.setSelectionEnd(chatingTextPane.getText().length());
    }//GEN-LAST:event_btnSendActionPerformed

    private void btnSendKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btnSendKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getModifiers() == KeyEvent.CTRL_MASK) {
            this.btnSendActionPerformed(null);
        }
    }//GEN-LAST:event_btnSendKeyPressed

    private void btnFaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFaceActionPerformed
        // TODO add your handling code here:
        ChatDialog chatDialog = (ChatDialog) map.get("chatDialog");
        //Log.println("x: " + chatDialog.getX() + " y: " + chatDialog.getY());
        QQFaceDialog qqface = QQFaceDialog.getInstance();
        qqface.setTextEditor(this.editorPane);
        if (!qqface.isVisible()) {
            qqface.setBounds(chatDialog.getX() + ChatPanelBottom.getX() + 5, chatDialog.getY() + ChatPanelBottom.getY() - 40, qqface.getWidth(), qqface.getHeight());
            qqface.setVisible(true);
        } else {
            qqface.setVisible(false);
        }
    }//GEN-LAST:event_btnFaceActionPerformed
    private JPopupMenu popupMenu = new JPopupMenu();
    private JMenuItem enabledItem = new JMenuItem("接收群信息");
    private JMenuItem disabledItem = new JMenuItem("禁止群信息");
    private final ImageIcon enIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
            getClass().getResource("/iqq/res/images/icon/group_enabled.png")));
    private final ImageIcon disIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(
            getClass().getResource("/iqq/res/images/icon/group_disabled.png")));
    private void btnEnabledActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnabledActionPerformed
        // TODO add your handling code here:
        if (popupMenu.isVisible()) {
            return;
        }
        enabledItem.setIcon(enIcon);
        disabledItem.setIcon(disIcon);
        popupMenu.add(enabledItem);
        popupMenu.addSeparator();
        popupMenu.add(disabledItem);
        popupMenu.setVisible(true);
        Component c = (Component) evt.getSource();
        popupMenu.show(c, -1, c.getHeight());

        enabledItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnEnabled.setIcon(enIcon);
                GroupUtil.getInstance().delete(group.getNumber());
            }
        });

        disabledItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnEnabled.setIcon(disIcon);
                GroupUtil.getInstance().add(group.getNumber());
            }
        });
    }//GEN-LAST:event_btnEnabledActionPerformed

    private void editorPaneKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editorPaneKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER && evt.getModifiers() == KeyEvent.CTRL_MASK) {
            this.btnSendActionPerformed(null);
        }
    }//GEN-LAST:event_editorPaneKeyPressed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ChatPanelBottom;
    private javax.swing.JPanel ChatPanelTop;
    private javax.swing.JToolBar ChatToolBarTop;
    private javax.swing.JButton btnEnabled;
    private javax.swing.JButton btnFace;
    private javax.swing.JButton btnSend;
    private javax.swing.JTextPane chatingTextPane;
    private javax.swing.JEditorPane editorPane;
    private javax.swing.JPanel groupTreePanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblFace;
    private javax.swing.JLabel lblLnick;
    private javax.swing.JLabel lblUsername;
    // End of variables declaration//GEN-END:variables

    private void initGroupMembers() {
        JLabel loading = new JLabel("加载中...", JLabel.CENTER);
        loading.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(
                getClass().getResource("/iqq/res/images/icon/flash.gif"))));
        groupTreePanel.add(loading);
        Runnable r = new Runnable() {

            @Override
            public void run() {
                List<Member> memberList = GroupService.getInstance().downloadMemberList(group.getCode());

                if (memberList == null || memberList.isEmpty()) {
                    return;
                }
                Log.println("initGroupMembers size:" + memberList.size());
                DefaultMutableTreeNode root = new DefaultMutableTreeNode("Members");
                IconTreeNode itn = null;
                for (Member m : memberList) {
                    try {
                        itn = new IconTreeNode(m);
                    } catch (Exception ex) {
                        Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    root.add(itn);
                }
                groupMemberTree = new JTree(root);

                groupMemberTree.setRootVisible(true);
                DefaultTreeCellRenderer ceeRender = new MyDefaultTreeCellRenderer();
                groupMemberTree.setCellRenderer(ceeRender);
                groupTreePanel.removeAll();
                groupTreePanel.add(new JScrollPane(groupMemberTree));

            }
        };

        ThreadUtil.submit(r);

    }
}
